package com.zx._12_算法;

import java.util.Arrays;

public class Nums {

    public static int[] nums = {6, 1, 9, 8, 1, 6, 3, 7, 4, 9, 2};

    public static int[] res;

    static {
        // 升序
        res = nums.clone();
        Arrays.sort(res);
    }


    public static void print() {
        System.out.println("排序后的结果：" + Arrays.toString(nums));
        check(true);
    }

    public static void print(int[] arr) {
        System.out.println("排序后的结果：" + Arrays.toString(arr));
    }

    public static void printRes() {
        System.out.println(Arrays.toString(res));
    }

    private static void check(boolean shengxu) {
        for (int i = 0; i < res.length; i++) {
            if (shengxu) {
                if (nums[i] != res[i]) {
                    throw new RuntimeException("排序结果不正确");
                }
            } else {
                if (nums[res.length - i - 1] != res[i]) {
                    throw new RuntimeException("排序结果不正确");
                }
            }

        }
    }

    /**
     * 降序比较
     */
    public static void printDown() {
        printDown(false);
    }

    public static void printDown(boolean shangxu) {
        check(shangxu);
        System.out.println("排序后的结果：" + Arrays.toString(nums));
    }

    public static void swap(int[] nums, int a, int b) {
        int tmp = nums[a];
        nums[a] = nums[b];
        nums[b] = tmp;
    }
}
